package view.images;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class ImageFactory {

    private final String iconpath;
    
    private static ImageFactory instance = null;

    public ImageFactory() {
        iconpath = "/view/images/";
    }

    public static ImageFactory getInstance() {
        if (instance == null) {
            instance = new ImageFactory();
        }
        return instance;
    }

    public ImageIcon getImageIcon20x20(final String imagem) {
        ImageIcon img = new ImageIcon(getClass().getResource(iconpath + imagem));
        return new ImageIcon(img.getImage().getScaledInstance(20, 20, 100));
    }

    public ImageIcon getImageFull(final String imagem) {
        ImageIcon img = new ImageIcon(getClass().getResource(iconpath + imagem));
        return img;
    }

    public ImageIcon getImageIcon400x300(File imagem) {
        BufferedImage image = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
        try {
            if (imagem.isFile()) {
                image = ImageIO.read(imagem);
            } else {
                JOptionPane.showMessageDialog(null, "Arquivo inválido!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        } catch (IOException ex) {
            Logger.getLogger(ImageFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
        ImageIcon img = new ImageIcon(image);
       return new ImageIcon(img.getImage().getScaledInstance(400, 300, 100));
    }

    public ImageIcon getImageIcon30x30(final String imagem) {
        ImageIcon img = new ImageIcon(getClass().getResource(iconpath + imagem));
        return new ImageIcon(img.getImage().getScaledInstance(30, 30, 100));
    }

    public ImageIcon getImageIcon40x40(final String imagem) {
        ImageIcon img = new ImageIcon(getClass().getResource(iconpath + imagem));
        return new ImageIcon(img.getImage().getScaledInstance(40, 40, 100));
    }

    public ImageIcon getImageIconXY(final String imagem, int x, int y) {
        ImageIcon img = new ImageIcon(getClass().getResource(iconpath + imagem));
        return new ImageIcon(img.getImage().getScaledInstance(x, y, 100));
    }
}
